package top.fengyulou.xiaofeng.config.interceptor;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import org.springframework.web.servlet.HandlerInterceptor;
import top.fengyulou.xiaofeng.common.UserUtils;
import top.fengyulou.xiaofeng.service.MenuService;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 后台数据封装拦截器
 */
@Component
@Slf4j
public class AdminDataInterceptor implements HandlerInterceptor {

    @Resource
    private MenuService menuService;

    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
        //获取用户数据
        request.setAttribute("loginUser", UserUtils.getUser(request));
        //获取菜单列表
        request.setAttribute("adminMenuList",menuService.leftMenuList());
        return true;
    }
}
